package com.rainy.cloud.jdbc.mybatis.configuration;

import com.rainy.cloud.jdbc.mybatis.handler.MybatisHandler;
import com.rainy.cloud.jdbc.mybatis.properties.JdbcProperties;
import com.rainy.cloud.jdbc.mybatis.properties.MybatisProperties;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.aop.Advisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.interceptor.TransactionInterceptor;
import tk.mybatis.spring.mapper.MapperScannerConfigurer;

import javax.sql.DataSource;

@Import({JdbcProperties.class, MybatisProperties.class})
@Configuration
public class MybatisConfiguration extends MybatisHandler {

    @Bean
    public DataSource dataSource(JdbcProperties jdbcProperties){
        return super.dataSource(jdbcProperties);
    }

    @Bean(name="mapperHelper")
    public MapperScannerConfigurer mapperHelper(MybatisProperties mybatisProperties){
        return super.mapperHelper(mybatisProperties);
    }

    @Bean(name = "sqlSessionFactory")
    public SqlSessionFactory sqlSessionFactoryBean(JdbcProperties jdbcProperties, MybatisProperties mybatisProperties) {
        return super.sqlSessionFactoryBean(jdbcProperties, mybatisProperties);
    }

    @Bean
    public PlatformTransactionManager transactionManager(JdbcProperties jdbcProperties) {
        return super.transactionManager(jdbcProperties);
    }

    @Bean
    public TransactionInterceptor txAdvice(JdbcProperties jdbcProperties) {
        return super.txAdvice(jdbcProperties);
    }

    @Bean
    public Advisor txAdviceAdvisor(JdbcProperties jdbcProperties, MybatisProperties mybatisProperties) {
        return super.txAdviceAdvisor(jdbcProperties, mybatisProperties);
    }

}
